home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 8 / FM Towns Free Software Collection 8.iso / t_os / gpen32k / source / lib / osrc / fsel2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-01  |  4.7 KB  |  215 lines

  1. /*
  2.         Free File Selector V0.24
  3.         ファイルセレクタ快適操作版
  4.                                 Copyright(C)1993,1994 Okome
  5. */
  6.  
  7. #include    <stdio.h>
  8. #include    <string.h>
  9. #include    <dos.h>
  10. #include    <direct.h>
  11. #include    <EGB.H>
  12. #include    <MOS.H>
  13. #include    <kkstr2.h>
  14. #include    <Normlib.h>
  15. #include    <okome.h>
  16.  
  17. #define    FX4        340
  18. #define    FY4        220
  19. #define FX3        (FX4-1)
  20. #define    FY3        (FY4-1)
  21. #define FX2        (FX1+FX3)
  22. #define    FY2        (FY1+FY3)
  23. #define RX1        (FX2-100)
  24. #define RY1        (FY2-21)
  25. #define RX2        (RX1+52)
  26. #define RY2        (RY1+18)
  27.  
  28. extern char work[];
  29. static int FX1=120,FY1=80;
  30.  
  31. int WIN_MEN_bar(char *tt, int x1, int y1, int x2)
  32. {
  33.     boxbf( x1,y1,x1+x2,y1+15,8,9 );
  34.     boxf(x1,y1,x1+strlen(tt)*6+45,y1+15,8);
  35.     boxbf(x1,y1,x1+15,y1+15,8,4);
  36.     font12(x1+28,y1+13,tt,15);
  37.     return (0);
  38. }
  39.  
  40. static void dvsym(int drv)
  41. {
  42.     char w[2];
  43.     boxbf(FX1+40, FY1+20, FX1+70, FY1+37, 8,15);
  44.     w[0]='A'+drv-1;
  45.     w[1]=0;
  46.     symbol(FX1+51,FY1+36, w, 16, 8);
  47. }
  48.  
  49. static void dvpos(int s, int fx, struct _find_t fls[])
  50. {
  51.     int i,j;
  52.     boxf( FX1+8,FY1+44,FX2-24,FY2-24, 8 );
  53.     boxbf( FX2-20,FY1+44,FX2-4,FY2-24, 8, 9 );
  54.     if (fx!=0)
  55.     {
  56.         j = FY1+44+(FY2-FY1-68)*(s/3)/((fx+2)/3);
  57.         i = j+(FY2-FY1-68)*8/((fx+2)/3);
  58.         if (i > FY2-24)
  59.             i = FY2-24;
  60.         boxbf( FX2-20,j,FX2-4, i, 8, 15 );
  61.         ubox2( FX2-19,j+1,FX2-5, i, 15, 8 );
  62.         for (i = 0; i<3*8 && s+i<fx; i++)
  63.         {
  64.             EGB_color( work, 0, ( fls[i+s].attrib & _A_SUBDIR ) ? 14: 15 );
  65.             print( FX1+9+(i % 3)*8*13, FY1+63+i/3*18, fls[i+s].name );
  66.         }
  67.     } else {
  68.         symbol(FX1+20,FY1+80,"File not found.",16,2);
  69.     }
  70. }
  71.  
  72. static int dvget( struct _find_t fls[])
  73. {
  74.     int fx = 0;
  75.     struct _find_t fla;
  76.     if (_dos_findfirst("*.*",_A_ARCH | _A_NORMAL | _A_SUBDIR | _A_RDONLY, &fla )==0)
  77.      {
  78.          do {
  79.              fls[fx] = fla;
  80.              fx++;
  81.          }    while (_dos_findnext(&fla)==0 && fx<512);
  82.      }
  83.      return (fx);
  84. }
  85.  
  86. int OKM_fsel(char *fna, char *msg, unsigned int drv)
  87. {
  88.     int i, fx, s=0, r=1, mb, mx, my, dmx, dmy, p, k, t=1;
  89.     unsigned int edr, drb;
  90.     struct _find_t fls[512];
  91. /*    struct _diskfree_t fre;    */
  92. /*    char w[8];    */
  93.     p = EGB_getWritePage( 0, 0 );
  94.     KAN_getMode(&k);
  95.     KAN_setMode(0x20000);
  96.     EGB_writePage( work, 0 );
  97.     MOS_disp(0);
  98.     OKM_gth( FX1,FY1, FX2,FY2, 1 );
  99.     boxbf( FX1,FY1,FX2,FY2, 8,15 );
  100.     WIN_MEN_bar( msg,FX1,FY1,FX3 );
  101.     boxb(FX1+20, FY1+20, FX1+90, FY1+37, 8);
  102.     boxb( RX1, RY1, RX2, RY2, 8 );
  103.     font12(RX1+12, RY2-3,"実 行",8);
  104.     if (drv==0)
  105.         _dos_getdrive(&drv);
  106.     else {
  107.         if (drv>='a' && drv<='z')
  108.             drv -= 'a'-1;
  109.         if (drv>='A' && drv<='Z')
  110.             drv -= 'A'-1;
  111.     }
  112.     _dos_setdrive(drv,&edr);
  113.     _dos_getdrive(&drv);
  114.     dvsym(drv);
  115. /*    _dos_getdiskfree( drv, &fre );
  116.     font12(FX1+100,FY1+36, _itoa( fre.*fre. ,w,10), 8);    */
  117.     fx = dvget(fls);
  118.     dvpos(0, fx, fls);
  119.     boxb( FX1+16, FY2-20, FX1+128, FY2-2, 8 );
  120.     MOS_disp(1);
  121.     do {
  122.         MOS_rdpos(&mb,&mx,&my);
  123.         keyin(FX1+22,FY2-19,fna,12,15,8,t);
  124.         t = 0;
  125.         if (mb==1)
  126.         {
  127.             if (mx>FX1+8 && mx<FX2-24 && my>FY1+45 && my<FY2-25)
  128.             {    /*    ファイル    */
  129.                 do    {
  130.                     dmx = (mx-FX1-9)/(8*13);
  131.                     dmy = (my-FY1-45)/18;
  132.                     i = s + dmx + dmy*3;
  133.                     MOS_rdpos(&mb,&mx,&my);
  134.                 }    while (mb!=0);
  135.                 if (i<fx && mx>FX1+8 && mx<FX2-24 && my>FY1+45 && my<FY2-25) {
  136.                     if ((fls[i].attrib & _A_SUBDIR)==0) {
  137.                         strcpy(fna,fls[i].name);
  138.                         t = 1;
  139.                     } else {
  140.                         MOS_disp(0);
  141.                         _chdir(fls[i].name);
  142.                         s = 0;
  143.                         fx = dvget(fls);
  144.                          dvpos(0, fx, fls);
  145.                         MOS_disp(1);
  146.                     }
  147.                 }
  148.             } else if (mx>FX2-20 && mx<FX2-4 && my>FY1+44 && my<FY2-24) {
  149.                 i = fx-19;
  150.                 if (i<3)
  151.                     i=3;
  152.                 i = ((i/3)*(my-FY1-44)/(FY2-FY1-68))*3;
  153.                 if (i!=s) {
  154.                     s = i;
  155.                     MOS_disp(0);
  156.                      dvpos(s, fx, fls);
  157.                     MOS_disp(1);
  158.                 }
  159.             }
  160.             if (my>FY1+20 && my<FY1+37) {
  161.                 if (mx>FX1+20 && mx<FX1+40) {
  162.                     do
  163.                     {
  164.                         drv--;
  165.                         if (drv==0)
  166.                             drv = edr;
  167.                         _dos_setdrive(drv,&edr);
  168.                         _dos_getdrive(&drb);
  169.                     }    while(drv!=drb);
  170.                     MOS_disp(0);
  171.                     dvsym(drv);
  172.                     fx = 0;
  173.                     MOS_disp(1);
  174.                     mbout(&i,&dmx,&dmy);
  175.                 }
  176.                 if (mx>FX1+70 && mx<FX1+90)
  177.                 {
  178.                     do {
  179.                         drv++;
  180.                         if (drv>edr)
  181.                             drv=1;
  182.                         _dos_setdrive(drv,&edr);
  183.                         _dos_getdrive(&drb);
  184.                     }    while(drv!=drb);
  185.                     MOS_disp(0);
  186.                     dvsym(drv);
  187.                     fx = 0;
  188.                     MOS_disp(1);
  189.                     mbout(&i,&dmx,&dmy);
  190.                 }
  191.                 if (mx>FX1+40 && mx<FX1+70) {
  192.                     MOS_disp(0);
  193.                     dvsym(drv);
  194.                     fx = dvget(fls);
  195.                     s = 0;
  196.                      dvpos(0, fx, fls);
  197.                     MOS_disp(1);
  198.                     mbout(&i,&dmx,&dmy);
  199.                 }
  200.             }
  201.             if (mx>RX1 && mx<RX2 && my>RY1 && my<RY2)
  202.                 r = 0;        /*    実行    */
  203.         }
  204.         if (mb==2 || (mb && mx>FX1 && mx<FX1+15 && my>FY1 && my<FY1+15))
  205.             r =-1;
  206.     }    while (r==1);
  207.     mbout(&mb,&mx,&my);
  208.     MOS_disp(0);
  209.     OKM_gth( FX1,FY1, FX2,FY2, 0 );
  210.     MOS_disp(1);
  211.     EGB_writePage( work, p );
  212.     KAN_setMode(k);
  213.     return (r);
  214. }
  215.